#include <bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 1e3+50;

int n, s, k;
unordered_set<int> S;
int a[N];



int main(int argc, char const *argv[])
{
	int t; scanf("%d", &t);
	for (int kk=0; kk<t; ++kk)
	{
		S.clear();
		scanf("%d%d%d", &n, &s, &k);
		for (int i=0; i<k; ++i)
		{
			int x; scanf("%d", &x);
			S.insert(x);
		}
		int ans = 1e9+50;
		for (int i=0; i<=1050; ++i)
		{
			if ((s+i<=n && !S.count(s+i)) || (s-i>=1 && !S.count(s-i)))
			{
				ans = min(ans, i);
				break;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}